import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';

import '../../viewmodel/iot/iot_list_view_model.dart';
import 'mattress_detail_page.dart';

class IotListPage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _IotListState();
}

class _IotListState extends BaseMvvmListState<IotListViewModel, IotListPage> {
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Colours.bg_color,
      appBar: AppBar(
        title: Text('智能设备'),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.end,
          children: [
            CommonText(item.name,
                textSize: 17,
                fontWeight: FontWeight.bold,
                textColor: Colors.blue),
            CommonText(item.connStatusName,
                textSize: 14,
                textColor: 1 == item.connStatus ? Colors.green : Colors.red)
          ],
        ),
        Container(
          height: 10,
        ),
        CommonText('设备编号：${item.deviceSn}'),
        Container(
          height: 10,
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            CommonText('绑定方式：${item.bindTypeName}'),
            CommonText('绑定位置：${item.position}'),
          ],
        ),
        Container(
          height: 10,
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            CommonText('设备类型：${item.typeName}'),
            CommonText('设备状态：${item.statusName}'),
          ],
        )
      ],
    )
        .onTap(() {
          if(item.type==5){
            Go().push(MattressDetailPage(iotCode: item.deviceSn??"",title: item.name??"",));
          }
    }).addToContainer(
        margin: EdgeInsets.symmetric(horizontal: 16),
        padding: EdgeInsets.all(10),
        decoration:
            BoxDecoration(color: Colors.white, borderRadius: 10.borderRadius));
  }

  @override
  IotListViewModel createViewModel() {
    return IotListViewModel(context);
  }

  @override
  Widget get separatorDivider => Container(
        height: 10,
      );

  @override
  EdgeInsets get listPadding => EdgeInsets.symmetric(vertical: 10);
}
